// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nick:"",
    imgUrl:"",
    sex:"",
    id:"",
    network:getApp().globalData['network'],
    balance:0
  },
  querymyBalance:function(id){
    var that = this;
    wx.request({
      url: "http://" + that.data.network + "/front/querymyBalance.php",
      method: "post",
      data: {
        user_id: id
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (data) {
        console.log(data);
        that.setData({
          balance:data.data[0].user_balance

        });
      }
    });
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var nick = wx.getStorageSync("nick");
    var imgUrl = wx.getStorageSync("imgUrl");
    var id = wx.getStorageSync("id");
    this.setData({
      nick:nick,
      imgUrl:imgUrl,
      id:id
    });
    that.querymyBalance(id);
  },
  tobalance:function(event){
    var that = this;
    wx.navigateTo({
      url:"/pages/balance/balance",
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage',that.data.balance)
      }
    });
  },
  tovip:function(){
    wx.navigateTo({
      url:"/pages/vip/vip"
      
    });
  },
  toorder:function(){
    wx.navigateTo({
      url:"/pages/order/order"
      
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})